<?php

$kegiatan = getListKegiatanBySektoral($_SESSION['idsektoral']);	

if ($kegiatan) {
	
	if (isset($_GET['success']) && ($_GET['success'] == "1")) {

			$o .= '<div class="alert alert-success">
					hapus kegiatan berhasil
					</div>';
					
	} elseif (isset($_GET['success']) && ($_GET['success'] == "0")) {
			
			$o .= '<div class="alert alert-error">
					hapus kegiatan gagal
				   </div>';
	}
	
	$o .= '<table class="table table-striped table-bordered table-condensed">
			<tr>
				<td><center>No</td>
				<td><center>Nama Kegiatan</td>
				<td><center>Kabupaten</td>
				<td><center>Sektoral</td>
				<td><center>Operator</td>
				<td colspan=4><center>Action</td>
			</tr>
	
		  ';
	
	$no = 1;
	
	foreach($kegiatan as $x) {
		
		$o .= '<tr>
					<td><center>'.$no.'</td>
					<td><center>'.$x['nama_kegiatan'].'</td>
					<td><center>'.$x['kabupaten'].'</td>
					<td><center>'.$x['sektoral'].'</td>
					<td><center>'.$x['username'].'</td>
					<td><center><a href="?page=detailkegiatan&id='.$x['idkegiatan'].'"><i class="icon-edit"></i>detail</a></td>
					<td><center><a href="?page=monitoring&id='.$x['idkegiatan'].'"><i class="icon-edit"></i>monitoring</a></td>
					<td><center><a href="?page=editkegiatan&id='.$x['idkegiatan'].'"><i class="icon-edit"></i>edit</a></td>
					<td><center><a href="?page=listkegiatan&action=delete&id='.$x['idkegiatan'].'"><i class="icon-remove"></i>hapus</a></td>
			  </tr>';
			  
		 
			  
		$no++;
		
	}

	$o .= '</table>';

} else {

	$o .= '<div class="alert alert-error">
		  <center>Data kosong</center>
		  </div>';
} 

echo $o;

if ($_GET['action'] == "delete") {
	
	$id = htmlentitties(mysql_real_escape_strinf($_GET['id']));
	
	$hapusKegiatan = deleteKegiatan($id);
	
	if ($hapusKegiatan) {
		
		$hapusMonitoring = deleteMonitoring($id);
		
		?>
		<script language="javascript">
		document.location="?page=listkegiatan&success=1";
		</script>
		<?php
		
	} else {
		
		?>
		<script language="javascript">
		document.location="?page=listkegiatan&success=0";
		</script>
		<?php
	}

}
